package cap.action;

import cap.bean.Counter;
import cap.dao.CounterDao;
import cap.dao.impl.CounterDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/counter")
public class CounterServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private CounterDao counterDao;

    public CounterServlet() {
        counterDao = new CounterDaoImpl();
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Counter counter=counterDao.getCounter();
        //request.setAttribute("counter", counter);
        PrintWriter out=response.getWriter();
        out.print(counter.getCount());
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
